package com.qfjy.wangfei;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @auther:wf
 * @date:2022/9/13 19:24
 * @version:1.0
 */
public class ProxyUntil {
    //动态代理对象工具类
    private Object target;

    public ProxyUntil(Object target) {
        this.target = target;
    }

    //获取代理目标
    public Object getTarget(){
        Object instance = Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        Object o = method.invoke(target, args);
                        return o;
                    }
                });
        return instance;
    }
}
